unit uConfiguraCT;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, JvExControls, JvXPCore, JvXPButtons, DB, ATXPtask, StdCtrls,
  Mask, ToolEdit, CurrEdit, JvLabel, DBClient, ExtCtrls, IniFiles;

type
  TfrmConfiguraCT = class(TForm)
    ClientDataSet1: TClientDataSet;
    JvLabel1: TJvLabel;
    JvLabel2: TJvLabel;
    JvLabel3: TJvLabel;
    JvLabel4: TJvLabel;
    JvLabel5: TJvLabel;
    JvLabel6: TJvLabel;
    JvLabel7: TJvLabel;
    JvLabel8: TJvLabel;
    JvLabel9: TJvLabel;
    JvLabel10: TJvLabel;
    JvLabel11: TJvLabel;
    JvLabel12: TJvLabel;
    JvLabel13: TJvLabel;
    edPOS_DT_DOC: TCurrencyEdit;
    edTAM_DT_DOC: TCurrencyEdit;
    edPOS_NUM_DOCI: TCurrencyEdit;
    edTAM_NUM_DOCI: TCurrencyEdit;
    edPOS_NUM_DOCF: TCurrencyEdit;
    edTAM_NUM_DOCF: TCurrencyEdit;
    edPOS_SER: TCurrencyEdit;
    edTAM_SER: TCurrencyEdit;
    edPOS_ESPECIE: TCurrencyEdit;
    edTAM_ESPECIE: TCurrencyEdit;
    edPOS_LANCAMENTO: TCurrencyEdit;
    edTAM_LANCAMENTO: TCurrencyEdit;
    edPOS_COD_PART: TCurrencyEdit;
    edTAM_COD_PART: TCurrencyEdit;
    edPOS_COD_MOD: TCurrencyEdit;
    edTAM_COD_MOD: TCurrencyEdit;
    edPOS_CFOP: TCurrencyEdit;
    edTAM_CFOP: TCurrencyEdit;
    edPOS_COMPLEMENTO: TCurrencyEdit;
    edTAM_COMPLEMENTO: TCurrencyEdit;
    edPOS_COD_CTA: TCurrencyEdit;
    edTAM_COD_CTA: TCurrencyEdit;
    edPOS_ALIQ: TCurrencyEdit;
    edTAM_ALIQ: TCurrencyEdit;
    edPOS_COD_OBS: TCurrencyEdit;
    edTAM_COD_OBS: TCurrencyEdit;
    XPSectionLabel1: TXPSectionLabel;
    JvLabel14: TJvLabel;
    JvLabel15: TJvLabel;
    JvLabel16: TJvLabel;
    JvLabel17: TJvLabel;
    JvLabel18: TJvLabel;
    JvLabel19: TJvLabel;
    JvLabel20: TJvLabel;
    JvLabel21: TJvLabel;
    JvLabel22: TJvLabel;
    JvLabel23: TJvLabel;
    JvLabel24: TJvLabel;
    JvLabel25: TJvLabel;
    JvLabel26: TJvLabel;
    edPOS_OBS1: TCurrencyEdit;
    edTAM_OBS1: TCurrencyEdit;
    edPOS_OBS2: TCurrencyEdit;
    edTAM_OBS2: TCurrencyEdit;
    edPOS_OBS3: TCurrencyEdit;
    edTAM_OBS3: TCurrencyEdit;
    edPOS_OBS4: TCurrencyEdit;
    edTAM_OBS4: TCurrencyEdit;
    edPOS_UF_CLIENTE: TCurrencyEdit;
    edTAM_UF_CLIENTE: TCurrencyEdit;
    edPOS_UF_ORIGEM_CTRC: TCurrencyEdit;
    edTAM_UF_ORIGEM_CTRC: TCurrencyEdit;
    edPOS_COD_MUN: TCurrencyEdit;
    edTAM_COD_MUN: TCurrencyEdit;
    edPOS_VALORCONTABIL: TCurrencyEdit;
    edTAM_VALORCONTABIL: TCurrencyEdit;
    edPOS_BCALCICMS: TCurrencyEdit;
    edTAM_BCALCICMS: TCurrencyEdit;
    edPOS_IMPOSTOICMS: TCurrencyEdit;
    edTAM_IMPOSTOICMS: TCurrencyEdit;
    edPOS_ISENTASICMS: TCurrencyEdit;
    edTAM_ISENTASICMS: TCurrencyEdit;
    edPOS_OUTRASICMS: TCurrencyEdit;
    edTAM_OUTRASICMS: TCurrencyEdit;
    edPOS_VLRAUXICMS: TCurrencyEdit;
    edTAM_VLRAUXICMS: TCurrencyEdit;
    JvLabel27: TJvLabel;
    JvLabel28: TJvLabel;
    JvLabel29: TJvLabel;
    JvLabel30: TJvLabel;
    JvLabel31: TJvLabel;
    JvLabel32: TJvLabel;
    JvLabel33: TJvLabel;
    JvLabel34: TJvLabel;
    JvLabel35: TJvLabel;
    JvLabel36: TJvLabel;
    JvLabel37: TJvLabel;
    JvLabel38: TJvLabel;
    JvLabel39: TJvLabel;
    edPOS_BASE_IPI: TCurrencyEdit;
    edTAM_BASE_IPI: TCurrencyEdit;
    edPOS_IPI: TCurrencyEdit;
    edTAM_IPI: TCurrencyEdit;
    edPOS_ISENTASIPI: TCurrencyEdit;
    edTAM_ISENTASIPI: TCurrencyEdit;
    edPOS_OUTRASIPI: TCurrencyEdit;
    edTAM_OUTRASIPI: TCurrencyEdit;
    edPOS_VLRAUXIPI: TCurrencyEdit;
    edTAM_VLRAUXIPI: TCurrencyEdit;
    edPOS_BASEICMSRETIDO: TCurrencyEdit;
    edTAM_BASEICMSRETIDO: TCurrencyEdit;
    edPOS_ICMSRETIDO: TCurrencyEdit;
    edTAM_ICMSRETIDO: TCurrencyEdit;
    edPOS_CONTRIBUINTE: TCurrencyEdit;
    edTAM_CONTRIBUINTE: TCurrencyEdit;
    edPOS_FORMI: TCurrencyEdit;
    edTAM_FORMI: TCurrencyEdit;
    edPOS_FORMF: TCurrencyEdit;
    edTAM_FORMF: TCurrencyEdit;
    edPOS_ISENTASRS: TCurrencyEdit;
    edTAM_ISENTASRS: TCurrencyEdit;
    edPOS_OUTRASRS: TCurrencyEdit;
    edTAM_OUTRASRS: TCurrencyEdit;
    edPOS_UF: TCurrencyEdit;
    edTAM_UF: TCurrencyEdit;
    JvLabel40: TJvLabel;
    JvLabel41: TJvLabel;
    JvLabel42: TJvLabel;
    JvLabel43: TJvLabel;
    JvLabel44: TJvLabel;
    JvLabel45: TJvLabel;
    ClientDataSet1Campo: TStringField;
    ClientDataSet1Posicao: TIntegerField;
    ClientDataSet1Tamanho: TIntegerField;
    JvXPButton1: TJvXPButton;
    Bevel1: TBevel;
    Image1: TImage;
    edDiretorio: TDirectoryEdit;
    JvLabel46: TJvLabel;
    procedure JvXPButton1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmConfiguraCT: TfrmConfiguraCT;

implementation

{$R *.dfm}

procedure TfrmConfiguraCT.JvXPButton1Click(Sender: TObject);
var
  ArqIni: TIniFile;
  i: Integer;
begin
  try
    ArqIni := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'CT.ini');

    for i := 0 to ComponentCount - 1 do begin
      if Components[i] is TCurrencyEdit then begin
        if copy(TCurrencyEdit(Components[i]).Name, 1, 5) = 'edPOS' then begin
          ArqIni.WriteInteger('POSICAO', Trim(copy(TCurrencyEdit(Components[i]).Name, 7, 30)), Trunc(TCurrencyEdit(Components[i]).Value));
        end else begin
          ArqIni.WriteInteger('TAMANHO', Trim(copy(TCurrencyEdit(Components[i]).Name, 7, 30)), Trunc(TCurrencyEdit(Components[i]).Value));
        end;
      end;
    end;
    ArqIni.WriteString('DIRETORIO', 'NOME', edDiretorio.Text);
  finally
    ArqIni.Free;
    Close;
  end;
end;

procedure TfrmConfiguraCT.FormActivate(Sender: TObject);
var
  ArqIni: TIniFile;
  i: Integer;
begin
  if FileExists(ExtractFilePath(Application.ExeName) + 'CT.ini') then begin
    try
      ArqIni := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'CT.ini');

      for i := 0 to ComponentCount - 1 do begin
        if Components[i] is TCurrencyEdit then begin
          if copy(TCurrencyEdit(Components[i]).Name, 1, 5) = 'edPOS' then begin
            TCurrencyEdit(Components[i]).Value := ArqIni.ReadInteger('POSICAO', Trim(copy(TCurrencyEdit(Components[i]).Name, 7, 30)), 0);
          end else begin
            TCurrencyEdit(Components[i]).Value := ArqIni.ReadInteger('TAMANHO', Trim(copy(TCurrencyEdit(Components[i]).Name, 7, 30)), 0);
          end;
        end;
      end;
      edDiretorio.Text := ArqIni.ReadString('DIRETORIO', 'NOME', '');
    finally
      ArqIni.Free;
    end;
  end;
end;

end.

